const cloud = require('@alipay/faas-server-sdk');
/**
 * 初始化购物车表
 */
async function createCollection(db) {
  const collectionResp = await db.getCollection('mall_shop_car');
  if(!collectionResp){
    collectionResp = await db.createCollection('mall_shop_car');
  }
  console.log('collectionResp:',collectionResp)
  return collectionResp;
}
exports.main = async (event, context) => {
  const db = cloud.database();
  const resp = await createCollection(db);
  if(resp){
  //新增订单
  const carResp = await db.collection('mall_shop_car').add({
    data: {
      "name": event.name,
      "price": event.price,
      "number":  event.number,
      "picUrl": event.picUrl,
      "productId": event.productId,
      "userId": event.userId,
      "status": "NORMAL",
      "shopeId": event.shopeId,
      "gmtCreate": Date.now(),
      "shopeName": event.shopeName,
      "description": event.description,
      "gmtModified": Date.now()
    }
  });
  console.log(`carResp:`, carResp);
  return carResp;
  }
};